home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- #
- # use CGI.pm and DBI external modules
- #
- # CGI.pm is part of standard perl distribution
- # DBI is available from www.cpan.org
- #
- # program uses CSV files to store data
- #
- # work in progress, inserts graphs generated with
- # GD::Graph library. server was down during MacHack
- # so we couldn't get it complied on Mac OS X
- #
-
- use CGI;
- use DBI;
- use CGI::Carp qw(fatalsToBrowser);
-
- my $q = new CGI;
-
- sub print_table {
-
- my $description = shift;
- my $variable = shift;
- my $graph = shift;
-
- #
- # set up for database access
- # ref: O'Reilley CGI Programming with Perl
- #
-
- my $dbdir = "/Library/WebServer/CGI-Executables";
- #my $dbdir = "C:/Documents and Settings/richard/My Documents/Projects/machack";
- my $dbh = DBI->connect("DBI:CSV:f_dir=$dbdir")
- or die "Can't connect: " . $DBI::errstr;
-
- my $sql = "select user, $variable from data order by $variable";
-
- my $sth = $dbh->prepare($sql)
- or die "Can't prepare: " . $dbh->errstr();
-
- $sth->execute()
- or die "Can not execute: " . $sth->errstr();
-
- my @row;
-
- print qq`
- <table border="0">
- <tr>
- <td>
- <table border="1">
- <tr><td>User</td><td>$description</td></tr>
- `;
-
- my $i = 0;
- my @list;
- my $msg_avg;
-
- while (@row = $sth->fetchrow_array()){
- @list[$i] = join( "</td><td>", @row) . "</td></tr>\n";
- $i++;
- }
-
- #while (@row = $sth->fetchrow_array()){
- ## print ("<tr><td>");
- # $msg_avg = int $row[1] / $row[2];
- # if ($variable eq "usage_avg_day"){
- # $msg_avg = int $msg_avg / 60;
- # }
- # @list[$i] = "<tr><td>" .$row[0] . "</td><td>" . $msg_avg . "</td></tr>\n
- #";
- ## @list[$i] = join( "</td><td>" , @row) . "</td></tr>\n";
- # print @list[$i];
- # $i++;
- #}
-
- while ($i >= 0){
- print ("<tr><td>");
- print @list[$i];
- $i--;
- }
-
- print qq`
- </td>
- </table>
- <td><img src="http://10.1.1.114/$graph"></td>
- </tr>
- </table>
- <br>
- `;
-
- $sth->finish;
-
- $dbh->disconnect;
- }
-
- sub print2{
-
- print ("<html><body><h1>blah</h1></body></html>\n");
-
- }
-
- #
- # tell browser what mime type file is
- #
-
- print $q->header("text/html");
-
- print qq`
- <html>
- <head>
- </head>
- <body bgcolor="FFCC33">
- `;
-
- print qq`
- <h2>Sorted by read messages</h2>
- `;
-
- &print_table("Read Messages", "read_msg_avg_day", "graph1.png");
-
- print qq`
- <h2>Sorted by sent messages</h2>
- `;
-
- &print_table("Sent Messages", "sent_msg_avg_day", "graph2.png");
-
- print qq`
- <h2>Sorted by usage</h2>
- `;
-
- &print_table("Usage", "usage_avg_day", "graph3.png");
-
- print qq`
- </body>
- </html>
- `;
-